package com.wpw.web;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @ClassName: CPUTest
 * @CreateDate: 2020-01-07 00:04
 * @author: wupengwei
 */
public class CPUTest {

    public static void main(String[] args) {
        List<List<Integer>> sumAddend = getSumAddend(36, 3);
        System.out.println(sumAddend);
        System.out.println(sumAddend.size());
    }

    private static List<List<Integer>> getSumAddend(int sum, int varCount) {
        int count = 0;
        int totalCount = 0;

        List<List<Integer>> groupList = new ArrayList<>();

        List<Integer> list;
        if (varCount == 3) {
            //三个变量类型
            for (int i = 0; i <= sum; i++) {
                for (int j = 0; j <= sum; j++) {
                    for (int m = sum - i - j; m >=0 ; m--) {
                        totalCount ++;
                        if (m + i + j == sum) {
                            list = new ArrayList<>();
                            list.add(i);
                            list.add(j);
                            list.add(m);
                            groupList.add(list);
                            count ++;
                            break;
                        }
                    }
                }
            }
        } else if (varCount == 2) {
            //两个变量
            for (int i = 0; i <= sum; i++) {
                totalCount ++;
                list = new ArrayList<>();
                list.add(i);
                list.add(sum - i);
                groupList.add(list);
                count ++;
            }
        }

        return groupList;
    }
}